package com.cppsu.cgx.libraryseatselection.controller;

import com.cppsu.cgx.libraryseatselection.common.api.CommonResult;
import com.cppsu.cgx.libraryseatselection.dto.SeatSelectionDetails;
import com.cppsu.cgx.libraryseatselection.dto.SeatSelectionDetailsParam;
import com.cppsu.cgx.libraryseatselection.dto.SeatSelectionParam;
import com.cppsu.cgx.libraryseatselection.entity.SeatSelection;
import com.cppsu.cgx.libraryseatselection.services.SeatSelectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: guibo
 * @Description:
 * @Date: Created in 9:35 2021/3/11
 * @Modified By:
 */
@Controller
@Api(tags = "选座管理")
@RequestMapping("/seatSelection")
@CrossOrigin()
public class SeatSelectionController {
    @Autowired
    SeatSelectionService seatSelectionService;

    @ApiOperation("按照条件搜索选座信息")
    @GetMapping(value = "/list")
    @ResponseBody
    @PreAuthorize("hasAnyAuthority('admin','user')")
    CommonResult<List<SeatSelection>> list(SeatSelectionParam seatSelectionParam){
        return CommonResult.success(seatSelectionService.list(seatSelectionParam));
    }
    @ApiOperation("新增")
    @PostMapping(value = "/add")
    @ResponseBody
    CommonResult<Integer> add(@RequestBody @Valid SeatSelectionParam seatSelectionParam){
        return CommonResult.success(seatSelectionService.add(seatSelectionParam));
    }

    @ApiOperation("更新")
    @PostMapping(value = "/update")
    @ResponseBody
    CommonResult<Integer> update(SeatSelectionParam seatSelectionParam){
        return CommonResult.success(seatSelectionService.update(seatSelectionParam));
    }
    @ApiOperation("批量删除")
    @PostMapping(value = "/delete")
    @ResponseBody
    CommonResult<Integer> delete(@RequestParam(value = "ids") List<Long> ids){
        return CommonResult.success(seatSelectionService.delete(ids));
    }

    @ApiOperation("批量退选")
    @PostMapping(value = "/returnSeat")
    @ResponseBody
    CommonResult<Integer> returnSeat(@RequestParam(value = "ids") List<Long> ids){
        return CommonResult.success(seatSelectionService.returnSeat(ids));
    }
    @ApiOperation("获取选座详情")
    @PostMapping(value = "/listSeatSelectionDetails")
    @ResponseBody
    CommonResult<List<SeatSelectionDetails>> listSeatSelectionDetails(SeatSelectionDetailsParam seatSelectionDetailsParam){
        return CommonResult.success(seatSelectionService.listSeatSelectionDetails(seatSelectionDetailsParam));
    }
}
